/**************************************************************************
 * @doc CORE
 * @module validt.C |  
 * Source code for the configuration validation functions.
 *
 * Product     :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :   
 * <nl>Notes       :
 *
 * @head3 Validation Functions |
 * @index | validt
 * @end
 *
 * Copyright (c) 1996-2000 by VeriFone Inc. All rights reserved.
 * 
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form 
 * or by any means whether electronic, mechanical, magnetic, optical, 
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * ------------------------------------------------------------------------
 $Log: /SoftPay/SPK2SIM/Source/Config/validt.c $
 * ------------------------------------------------------------------------
 ********************************************************************************/

#define VSVALIDT_C

#include <stdlib.h>
#include <applidl.h>
#include <aclconio.h>
#include <ctype.h>
#include <aclstr.h>
#include <string.h>
#include <aclutil.h>
#include <power.h>

#include <project.h>

/** /#define DEBUG_VSVALIDT*/
#ifdef DEBUG_VSVALIDT
#define DEBUG_95
#endif

#include <define.h>
#include <transact.h>
#include <validt.h>
#include <ztconf.h>
#include <confproto.h>
#include <gds.h>
#include <tblutil.h>
#include <confio.h>
#include <init.h>
#include <msg.h>
#include <msgfuncs.h>
#include <modemmsg.h>
#include <modem.h>
#include <comm.h>
#include <ui.h>
#include <print.h>
#include <spdebug.h>
#include <pinpad.h>
#include <vidnld.h>
#include <operate.h>
#include <mbtx3.h>
#include <funcids.h> /* vsk -- added custom initialisation of Pinpad */
#include <cct.h>
extern short inGetPINPadType(void);

extern VS_BOOL gfPPadPresent;   /* Global flag to determine if PinPad is present */

/********************************************************************************************* 
* @func VS_BOOL | inRange | 
*       Determines if a value is within a specified range 
*
* @parm int | inVal | 
*       The value to be tested
*
* @parm int | inLow | 
*       Low range 
*
* @parm int | inHigh | 
*       High range 
*
* @rdesc return values.
* @flag VS_BOOL |  VS_TRUE or VS_FALSE
* @end
**********************************************************************************************/

VS_BOOL inRange(int inVal,int inLow,int inHigh) {
    if (inVal >= inLow && inVal <= inHigh)
        return(VS_TRUE);
    else {
        /** /pdebug(("inRange Fld-%d,%d,%d",inVal, inLow, inHigh));*/
        return(VS_FALSE);
    }
}

/********************************************************************************************* 
* @func VS_BOOL | inIsDigits | 
*       Determines if a value is a numerical value 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag VS_BOOL |  VS_TRUE or VS_FALSE
* @end
**********************************************************************************************/

VS_BOOL inIsDigits(char* pchValue) {
    int i;

    for (i = 0; i < (int) strlen(pchValue); i++) {
        if (!isdigit(pchValue[i])) {
            /** /pdebug(("IsDigit Failed"));*/
            return(VS_FALSE);
        }
    }
    return(VS_TRUE);
}
/********************************************************************************************* 
* @func int | inRange_0TO1 | 
*       Determines if a value is a 1 or 0 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inRange_0TO1(char* pchValue) {
    int inRetVal = VS_ERR;

    /** /pdebug(("--inRange_0TO2--"));*/

    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 0, 1))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_0TO1_MSG21);

    return (inRetVal);
} 
/********************************************************************************************* 
* @func int | inRange_0TO2 | 
*       Determines if a value in the range of 0 to 2 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inRange_0TO2(char* pchValue) {
    int inRetVal = VS_ERR;


    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 0, 2))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_OTO2_MSG21);

    return (inRetVal);
} 
/********************************************************************************************* 
* @func int | inRange_0TO3 | 
*       Determines if a value in the range of 0 to 3 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inRange_0TO3(char* pchValue) {
    int inRetVal = VS_ERR;

    /** /pdebug(("--inRange_0TO3--"));*/

    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 0, 3))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_0TO3_MSG21);

    return (inRetVal);
} 

/********************************************************************************************* 
* @func int | inRange_1TO3 | 
*       Determines if a value in the range of 1 to 3 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inRange_1TO3(char* pchValue) {
    int inRetVal = VS_ERR;

    /** /pdebug(("--inRange_1TO3--"));*/

    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 1, 3))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_1TO3_MSG21);

    return (inRetVal);
} 

/********************************************************************************************* 
* @func int | inRange_0TO4 | 
*       Determines if a value in the range of 0 to 4 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inRange_0TO4(char* pchValue) {
    int inRetVal = VS_ERR;

    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 0, 4))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_0TO4_MSG21);

    return (inRetVal);
} 


/********************************************************************************************* 
* @func int | inRange_0TO5 | 
*       Determines if a value in the range of 0 to 5 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inRange_0TO5(char* pchValue) {
    int inRetVal = VS_ERR;

    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 0, 5))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_0TO5_MSG21);

    return (inRetVal);
} 

/********************************************************************************************* 
* @func int | inRange_0TO59 | 
*       Determines if a value in the range of 0 to 59 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/


int inRange_0TO59(char* pchValue) {
    int inRetVal = VS_ERR;

    /** /pdebug(("--inRange_0TO59--"));*/

    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 0, 59))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_OTO59_MSG21);

    return (inRetVal);
} /* End of inRange_0TO59 () */

/********************************************************************************************* 
* @func int | inRange_8TO10 | 
*       Determines if a value in the range of 8 to 10 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/


int inRange_8TO10(char* pchValue) {
    int inRetVal = VS_ERR;

    /** /pdebug(("--inRange_0TO59--"));*/

    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 8, 10))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_8TO10_MSG21);

    return (inRetVal);
} /* End of inRange_8TO10 () */

/********************************************************************************************* 
* @func int | inRange_0TOCST | 
*       Determines if a value is no more than the number of currency records
*       in the currency table 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inRange_0TOCST(char* pchValue) {
    int inRetVal = VS_ERR;
    int inSize;

    /** /pdebug(("--inRange_0TOMAX--"));*/

    inSize = inGetCSTTotRecs();
    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 0, inSize - 1))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_OTOCST_MSG21);

    return (inRetVal);
} /* End of inRange_0TOCST () */
/********************************************************************************************* 
* @func int | inRange_0TOLCT | 
*       Determines if a value is no more than the number of language records
*       in the language configuration table 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inRange_0TOLCT(char* pchValue) {
    int inRetVal = VS_ERR;
    int inSize;

    /** /pdebug(("--inRange_0TOMAX--"));*/

    inSize = inGetLCTTotRecs();
    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 0, inSize - 1))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_OTOLCT_MSG21);

    return (inRetVal);
} /* End of inRange_0TOSCT () */

/********************************************************************************************* 
* @func int | inPrintOptionVal | 
*       Determines if a value is a valid print option
*       Valid values are 0, 1, 2, 4 and 8
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inPrintOptionVal(char* pchValue) {
    int inRetVal = VS_ERR;

    if ((strn2int(pchValue, 2) == PRT_NONE) || (strn2int(pchValue, 2) == PRT_PROMPT) || (strn2int(pchValue, 2) == PRT_CUST) || (strn2int(pchValue, 2) == PRT_MERCH) || (strn2int(pchValue, 2) == PRT_BOTH_CONF_CUSTCOPY) || (strn2int(pchValue, 2) == PRT_BOTH_AUTO_CUSTCOPY))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_PRT_OPTION_MSG21);

    return (inRetVal);
} 

/********************************************************************************************* 
* @func int | inCommLinkVal | 
*       Determines if a value is a valid comm link value
*       Valid values are between 0 and 6
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inCommLinkVal(char* pchValue) {
    int inValue;
    int inRetVal = VS_ERR;

    /** /pdebug(("--inCommLinkVal--"));*/

    inValue = atoi(pchValue);

    if (inIsDigits(pchValue) && (inValue > 0 && inValue < 7))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_PRT_OPTION_MSG21);

    return (inRetVal);
} 

/********************************************************************************************* 
* @func int | inBatchNumVal | 
*       Determines if a value is a valid comm link value
*       Valid values are between 0 and 6
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inBatchNumVal(char* pchValue) {
    int inValue;
    int inRetVal = VS_ERR;

    /** /pdebug(("--inRange_0TO2--"));*/

    inValue = atoi(pchValue);

    if (inIsDigits(pchValue) && (inValue > 0))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(ZERO_ENTRY_NOT_ALLOWED_MSG21);

    return (inRetVal);
} 
/********************************************************************************************* 
* @func int | inMKeyVal | 
*       Determines if a value is a valid MKey
*       Valid values are btween 0 and 9
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inMKeyVal(char* pchValue) {
    int inRetVal = VS_ERR;

    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 0, 9))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_OTO9_MSG21);

    return (inRetVal);
} 
/********************************************************************************************* 
* @func int | inBaudRtVal | 
*       Determines if a value is a valid Baud Rate value
*       Valid values are between 0 and 7
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inBaudRtVal(char* pchValue) {
    int inRetVal = VS_ERR;


    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 0, 8))
        if (strn2int(pchValue, 1) != 1) /* 1 is not a valid value */
            inRetVal = VS_SUCCESS;

    if (inRetVal == VS_ERR)
        vdSGErrorMessage(VALID_BAUD_RATES_MSG21);

    return (inRetVal);
} 
/********************************************************************************************* 
* @func int | inPortFmtVal | 
*       Determines if a value is a valid Port Format
*       Valid values are 0, 2 and 13
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inPortFmtVal(char* pchValue) {
    int inValue;
    int inRetVal = VS_ERR;


    inValue = atoi(pchValue);

    if (inIsDigits(pchValue) && (inValue == 0 || inValue == 4 || inValue == 7))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_OTO7_MSG21);

    return (inRetVal);
}
/********************************************************************************************* 
* @func int | inBitVal | 
*       Determines if a value is a valid Bit value
*       Valid values are either 0 or 1
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inBitVal(char* pchValue) {
    int inRetVal = VS_ERR;

    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 0, 1))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_OOR1_MSG21);

    return (inRetVal);
}
/********************************************************************************************* 
* @func int | inTimeVal | 
*       Determines if a value is a valid time value
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inTimeVal(char* pchValue) {
    int inRetVal = VS_ERR;

    /** /pdebug(("--inTimeVal--"));*/

    /*
     *      Validate time string in HHMMSS format
     */
    if (inIsDigits(pchValue) && (strn2int(pchValue, 2) > 23 || strn2int(&pchValue[2], 2) > 59 || strn2int(&pchValue[4], 2) > 59))
        vdSGErrorMessage(INVALID_SETTLE_TIME_MSG21);
    else
        inRetVal = VS_SUCCESS;

    return (inRetVal);
} /* End of inTimeVal () */

/********************************************************************************************* 
* @func int | inBeepVal | 
*       Determines if a value is a valid Beep value, 0 or 1
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inBeepVal(char* pchValue) {
    /** /pdebug(("--inBeepVal--"));*/

    if (inBitVal(pchValue) != VS_SUCCESS)
        return(VS_ERR);

    /* 
     *      Set terminal beep on/off 
     */
    key_beeps((short) str2int(pchValue));

    return VS_SUCCESS;
} /* End of inBeepVal () */

/********************************************************************************************* 
* @func int | inP350ColModeVal | 
*       Determines if a value is a valid Printer column mode, 0, 1 or 2
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inP350ColModeVal(char* pchValue) {
    int inRetVal = VS_SUCCESS; 

    /** /pdebug(("--inP350ColModeVal--"));*/

    if (!(inIsDigits(pchValue) && inRange(atoi(pchValue), 1, 2)))
        inRetVal = VS_ERR;

    if (fZtExprConfReqd() == VS_TRUE)
        return (inRetVal);
    else if (inGetPrinterType() != NOPRINTER && fGetEnablePrinter() != NO) {
        if (inChkPrinterStatus(&obPrinter) == VS_SUCCESS) {
            vdSetP350ColMode(str2int(pchValue));
            inSelectTemplateFile(&obPrinter);
            p350ColumnMode(inGetP350ColMode());
        }
    }

    vdClearStatusMessage();
    return (inRetVal);
} /* End of inP350ColModeVal () */

/********************************************************************************************* 
* @func int | inP350LPIVal | 
*       Determines if a value is a valid Printer lines per inch, 8, 9 or 10
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inP350LPIVal(char* pchValue) {
    int inRetVal = VS_SUCCESS; 

    /** /pdebug(("--inP350LPIVal--"));*/

    if (inRange_8TO10(pchValue) != VS_SUCCESS)
        inRetVal = VS_ERR;

    if (fZtExprConfReqd() == VS_TRUE)
        return (inRetVal);
    else if (inGetPrinterType() != NOPRINTER && fGetEnablePrinter() != NO) {
        if (inChkPrinterStatus(&obPrinter) == VS_SUCCESS) {
            vdSetP350LinesPerInch(str2int(pchValue));
            p350LinesPerInch(inGetP350LinesPerInch());
        }
    }

    vdClearStatusMessage();
    return (inRetVal);
} /* End of inP350LPIVal () */
/********************************************************************************************* 
* @func int | inCkrdrPortVal | 
*       Determines if a value is a valid Check reader port, 1,3,5 or P
*       and Disable COM3 Trap in case it is active 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inCkrdrPortVal(char* pchValue) {
    char chVal;
    int inRetVal = VS_ERR;
    CCT_REC srCCTRecLocal;

    /** /pdebug(("--inCkrdrPortVal--"));*/

    chVal = *pchValue;
    if (chVal == '1') {
        if (inLoadConfRec(CCT_FILE_NAME, SIZE_CCT_REC, 0, (char *) &srCCTRecLocal) == VS_SUCCESS) {
            srCCTRecLocal.szTermPort[0] = chVal;
            inRetVal = VS_SUCCESS;
        } else
            vdSGErrorMessage(CCT_ERR_MSG21);
    } else
        vdSGErrorMessage(ENTER_1TO3_5_OR_P_MSG21);

    return (inRetVal);
} /* End of inCkrdrPortVal () */

/********************************************************************************************* 
* @func int | inCardTypeVal | 
*       Determines if a value is a valid card type, between -1 and 10
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inCardTypeVal(char* pchValue) {
    int inRetVal = VS_ERR;

#ifdef FLEET_DEFINED
    if (inIsDigits(pchValue) && inRange(atoi(pchValue), -1, 11))
    #else
        if (inIsDigits(pchValue) && inRange(atoi(pchValue), -1, 10))
        #endif
            inRetVal = VS_SUCCESS;
        else {
#ifdef FLEET_DEFINED
            vdSGErrorMessage(PLS_ENTER_0TO11_MSG21);
#else
            vdSGErrorMessage(PLS_ENTER_0TO10_MSG21);
#endif
        }
    return (inRetVal);
} /* End of inCardTypeVal() */


#ifdef PINPAD_DEFINED
/********************************************************************************************* 
* @func int | inPinPadTypeVal | 
*       Determines if a value is a valid PinPad type, between 0 and 9
*       If so, call the PinPad setup function and initialize the PinPad
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/
typedef int (*PFI_SHORT) (short );
int inPinPadTypeVal(char* pchValue) {
    int inValue;
    int inRetVal = VS_ERR;
    int inPinpadType = 0;

    inValue = atoi(pchValue);

    if (inIsDigits(pchValue) && (inValue >= 0) && (inValue <= 9)) {
        PFI_SHORT inPinPadSetup = (PFI_SHORT) NULL; /* vsk -- added custom initialisation of Pinpad */
        extern PFI inGetFunctionPointer(int inFieldID);
        // Save the original.  Need the new value for inInitializePinPad()
        inPinpadType = inGetPINPadType();
        vdSetPINPadType(inValue);
        /* vsk -- added custom initialisation of Pinpad */
        if ((inPinPadSetup = inGetFunctionPointer(SETUP_PINPAD)) != NULL_PFI)
            inPinPadSetup(inGetPINPadType()); /* Note: Sets global flag gfPPadPresent */
        else
            inSetupPinPad(inGetPINPadType()); /* Note: Sets global flag gfPPadPresent */

        /* 
         * Use PinPad object function pointers to:
         * - Initialize the PinPad
         * - Set up the PinPad idle prompt
         */
        if ((inValue != NO_PINPAD) && gfPPadPresent)
            inRetVal = inInitializePinPad();
        else
            inRetVal = VS_SUCCESS;

        vdSetPINPadType(inValue);/* vsk -- added custom initialisation of Pinpad */
    } else
        vdSGErrorMessage(PLS_ENTER_0TO9_MSG21);

    return (inRetVal);
} /* End of inPinPadTypeVal() */

/********************************************************************************************* 
* @func int | inPinPadBaudVal | 
*       Determines if a value is a valid PinPad baud rate value, 
*       between 2 and 6 (1200, 2400, 4800, 9600, 19200)
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/
int inPinPadBaudVal(char* pchValue) {
    int inRetVal = VS_ERR;

    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 2, 6))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PINPAD_BAUD_ERR_MSG21);
    return (inRetVal);
} /* End of inPinPadBaudVal() */

/********************************************************************************************* 
* @func int | inPinPadFmtVal | 
*       Determines if a value is a valid PinPad format value, 
*          between  0  and 4 (Fmt_A7E1, Fmt_A7N1, Fmt_A7O1, Fmt_A8E1, Fmt_A8N1)
*       or between 10 and 14 (same as each of above with "| Fmt_auto" added)
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/
int inPinPadFmtVal(char* pchValue) {
    int inRetVal = VS_ERR;

    if ((inIsDigits(pchValue) && inRange(atoi(pchValue), 0, 4)) || (inIsDigits(pchValue) && inRange(atoi(pchValue), 10, 14)))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PINPAD_FMT_ERR_MSG21);
    return (inRetVal);
} /* End of inPinPadFmtVal() */


#endif /* PINPAD_DEFINED */

/********************************************************************************************* 
* @func int | inOpenTAmtVal | 
*       Determines if a value is a valid Open Tab Amount value, 
*       between 1 and 325 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/
int inOpenTAmtVal(char* pchValue) {
    int inRetVal = VS_ERR;

    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 1, 325))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_AMT_RANGE_MSG);
    return (inRetVal);
} /* End of inOpenTAmtVal() */
/********************************************************************************************* 
* @func int | inAutoAnswerVal | 
*       Determines if a value is a valid Auto Answer value, 0 or 1
*       Initiates modem for auto answer if TRUE.
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inAutoAnswerVal(char* pchValue) {
    int inRetVal = VS_SUCCESS;
    MODEM_OBJECT* obModem;
    //TRANSACTION_OBJECT obTran;
    //char szBuffer[10];
    /** /pdebug(("--inAutoAnswerVal--"));*/

    if (inBitVal(pchValue) != VS_SUCCESS)
        return(VS_ERR);


#ifdef MOBITEX_DEFINED
    if (inGetRadioCommHost() != VS_ERR && srGDS.fWirelessModem) {
        // We do not support Host Initiated downloads with radio modem
        vdDisplayMessageFromFile(TRANS_NOT_ALLWD_ERR_MSG, ERROR_MSG);
        return(VS_ERR);
    }
#endif

    if (srGDS.fLandLine) {
        if (srGDS.fHandHeld)
            while (get_dock_status() == HANDHELD_UNDOCKED && inRetVal == VS_SUCCESS) {
                vdDisplayWarningMsg(MUST_DOCK_TERMINAL_MSG21);
                if (act_kbd_pending_test(KEY_CANCEL)) {
                    vdSetTranError(TXN_CANCELLED);
                    return(VS_ERR);
                }
            }
    }

    if (fZtExprConfReqd() != VS_TRUE) {
        inInitializeComm(MODEM_COMM);

        obModem = (MODEM_OBJECT *) obCommunication.Data;

        if (inOpenMDMCommun(&obCommunication) == VS_ERR)
            return(VS_ERR);

        /* Set auto answer on/off */
        if (str2int(pchValue) == 0) {
            if (inAutoAnswerOff() != VS_SUCCESS)
                return(VS_ERR);
        } else
            inAutoAnswerOn(obModem->hModem);
    }

    return VS_SUCCESS;
} /* End of inAutoAnswerVal() */



/********************************************************************************************* 
* @func int | inNumRingsVal | 
*           Sets the number of rings allowed for auto-answer
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/
int inNumRingsVal(char* pchValue) {
    MODEM_OBJECT* obModem;
    int inNumRings;
    int inRetVal = VS_SUCCESS;
    /** /pdebug(("--inNumRingsVal--"));*/

    if (srGDS.fLandLine) {
        if (srGDS.fHandHeld)
            while (get_dock_status() == HANDHELD_UNDOCKED && inRetVal == VS_SUCCESS) {
                vdDisplayWarningMsg(MUST_DOCK_TERMINAL_MSG21);
                if (act_kbd_pending_test(KEY_CANCEL)) {
                    vdSetTranError(TXN_CANCELLED);
                    return(VS_ERR);
                }
            }
    }



    if ((inNumRings = str2int(pchValue)) > 99) {
        inNumRings = 99;
        strcpy(pchValue, "99");
    }


    /* If auto-answer on, then set number of rings */
    if (fZtExprConfReqd() != VS_TRUE) {
        if (fGetAutoAnswer()) {
            inInitializeComm(MODEM_COMM);
            obModem = (MODEM_OBJECT *) obCommunication.Data;

            vdSetNumOfRings(inNumRings);

            if (inOpenMDMCommun(&obCommunication) == VS_ERR)
                return(VS_ERR);
        }
    }
    return VS_SUCCESS;
}

/********************************************************************************************* 
* @func int | inCheckEntryModeVal | 
*       Determines if a value in the range of 1 to 3 
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inCheckEntryModeVal(char* pchValue) {
    int inRetVal = VS_ERR;

    /** /pdebug(("--inRange_1TO3--"));*/

    if (inIsDigits(pchValue) && inRange(atoi(pchValue), 1, 3))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_1TO3_MSG21);

    return (inRetVal);
} 


/********************************************************************************************* 
* @func int | inShortVal | 
*       Determines if a value is a valid comm link value
*       Valid values are between 0 and 6
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inShortVal(char* pchValue) {
    int inValue;
    int inRetVal = VS_ERR;

    /** /pdebug(("--inShortVal--"));*/

    if (strlen(pchValue) < 5)
        inRetVal = VS_SUCCESS;
    else if (strlen(pchValue) > 5)
        inRetVal = VS_ERR;
    else {
        if (pchValue[0] < 3)
            inRetVal = VS_SUCCESS;
        else if (pchValue[0] > 3)
            inRetVal = VS_ERR;
        else {
            inValue = atoi(&pchValue[1]);
            if (inValue > 2767)
                inRetVal = VS_ERR;
            else
                inRetVal = VS_SUCCESS;
        }
    }
    if (inRetVal == VS_ERR)
        vdSGErrorMessage(INVALID_ENTRY_MSG);

    return (inRetVal);
} 


/********************************************************************************************* 
* @func int | inLongVal | 
*       Determines if a value is a valid comm link value
*       Valid values are between 0 and 6
*
* @parm char * | pchValue | 
*       The value to be tested
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inLongVal(char* pchValue) {
    long lnValue;
    int inRetVal = VS_ERR;

    /** /pdebug(("--inShortVal--"));*/

    if (strlen(pchValue) < 10)
        inRetVal = VS_SUCCESS;
    else if (strlen(pchValue) > 10)
        inRetVal = VS_ERR;
    else {
        if (pchValue[0] < 2)
            inRetVal = VS_SUCCESS;
        else if (pchValue[0] > 2)
            inRetVal = VS_ERR;
        else {
            lnValue = atol(&pchValue[1]);
            if (lnValue > 147483647)
                inRetVal = VS_ERR;
            else
                inRetVal = VS_SUCCESS;
        }
    }
    if (inRetVal == VS_ERR)
        vdSGErrorMessage(INVALID_ENTRY_MSG);

    return (inRetVal);
} 


int inMANVal(char* pchValue) {
    int inRetVal = VS_ERR;
    int x;

    x = 0;

    while (pchValue[x]) {
        if (!(isdigit(pchValue[x]))) {
            vdSGErrorMessage(INVALID_ENTRY_MSG);

            return(VS_ERR);
        }
        x++;
    }



    if ((str2long(pchValue) >= 100000) && (str2long(pchValue) <= 16777216))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(INVALID_ENTRY_MSG);

    return(inRetVal);
}



int inRSSIVal(char* pchValue) {
    
#ifdef MOBITEX_DEFINED
	int inRetVal;

    if (srGDS.fWirelessActive == VS_FALSE && srGDS.fWirelessModem == VS_TRUE) {
        // If we are a wireless terminal with a wireless host and we
        // did not have a signal before but they have now changed the RSSI
        // threshold we need to see srGDS.fWirelessActive so idle_exit()
        // can init the radio modem for us.

        inRetVal = inGetRadioCommHost();

        if (inRetVal != VS_ERR) {
            if (inLoadDefaultHost(inRetVal) != VS_SUCCESS)
                return (VS_ERR);

            if (obCommunication.inLinkType == MOBITEX_COMM)
                srGDS.fWirelessActive = VS_TRUE;

            if (obCommunication.inDeinitialize)
                obCommunication.inDeinitialize(&obCommunication);
        } /* end if Wireless host */
    } /* end if Wireless not active and Wireless terminal */

#endif
    return(VS_SUCCESS);
} /* inRSSIVal() */


int inAATVal(char* pchValue) {
    TRANSACTION_OBJECT obTempTran;

    if (inBaudRtVal(pchValue) == VS_SUCCESS) {
        if (fZtExprConfReqd() != VS_TRUE)
            return(inAutoAnswerInit(&obTempTran));
        else
            return(VS_SUCCESS);
    } else
        return(VS_ERR);
} /* end func inAATVal() */


int inAATFmtVal(char* pchValue) {
    TRANSACTION_OBJECT obTempTran;

    if (inPortFmtVal(pchValue) == VS_SUCCESS) {
        if (fZtExprConfReqd() != VS_TRUE)
            return(inAutoAnswerInit(&obTempTran));
        else
            return(VS_SUCCESS);
    } else
        return(VS_ERR);
} /* end func inAATFmtVal() */


int inNumStrVal(char* pchValue) {
    int inRetVal = VS_ERR;

    if (inIsDigits(pchValue))
        inRetVal = VS_SUCCESS;
    else
        vdSGErrorMessage(PLS_ENTER_NUM_RANGE_MSG);

    return (inRetVal);
} /* end func inNumStrVal() */

#undef VSVALIDT_C
